<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/templates/template.xhtml">
	<ui:define name="pageTitle">Menu principal</ui:define>
	<ui:define name="pageHeader">SisExercicio</ui:define>
	<ui:define name="body">
		<h:form id="form">
			<p:panel header="Buscar vendas" styleClass="painelBuscarVendas">
				<h:panelGrid columns="1">
					<h:panelGrid columns="7">
						<h:outputLabel for="calendarioInicial" value="Data inicial: "
							styleClass="nomeAtributos" />
						<p:calendar id="calendarioInicial"
							value="#{beanVenda.dataInicial}" />
						<h:outputLabel value="   " />
						<h:outputLabel for="calendarioFinal" value="Data final: "
							styleClass="nomeAtributos" />
						<p:calendar id="calendarioFinal" value="#{beanVenda.dataFinal}" />
						<p:commandButton value="Buscar"
							action="#{beanVenda.buscarVendas}"
							update=":form:Listarvendas">
							<f:ajax onevent="click" render="idValorTotal" />
						</p:commandButton>
						<p:commandButton value="Limpar" disabled="true"/>
					</h:panelGrid>
					<h:panelGrid columns="3">
						<p:selectOneRadio value="#{beanVenda.flagStatusVenda}">
							<f:selectItem itemLabel="Vendas canceladas" itemValue="1"/>
							<f:selectItem itemLabel="Vendas efetivadas" itemValue="0"/>
							<f:selectItem itemLabel="Todas as vendas" itemValue="2"/>
						</p:selectOneRadio>
						<h:outputText value="Total das vendas: " styleClass="textoGrande"/>
						<h:outputText id="idValorTotal" value="#{beanVenda.valorTotal}"
							styleClass="textoGrande">
							<f:convertNumber currencyCode="BRL" type="currency" />
						</h:outputText>
					</h:panelGrid>
					<p:dataTable id="Listarvendas" var="venda"
						value="#{beanVenda.listaVendas}" emptyMessage="Sem registros"
						selection="#{beanVenda.vendaSelecionada}"
						rowKey="#{venda.vendaId}" rows="10" paginator="true"
						styleClass="colunaGrande">
						<f:facet name="header">Lista de vendas</f:facet>
						<p:column selectionMode="single"
							style="width:25px;text-align:center">
						</p:column>
						<p:column styleClass="colunaId">
							<f:facet name="header">Id</f:facet>
							#{venda.vendaId}
						</p:column>
						<p:column styleClass="colunaData">
							<f:facet name="header">Data</f:facet>
							<p:outputLabel value="#{venda.dataVenda}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</p:outputLabel>
						</p:column>
						<p:column styleClass="colunaNome" filterBy="#{venda.cliente.nome}">
							<f:facet name="header">Cliente</f:facet>
							#{venda.cliente.nome}
						</p:column>
						<p:column styleClass="colunaValor">
							<f:facet name="header">Valor total</f:facet>
							<p:outputLabel value="#{venda.valorTotal}">
								<f:convertNumber currencyCode="BRL" type="currency" />
							</p:outputLabel>
						</p:column>
						<p:column>
							<f:facet name="header">Status</f:facet>
							<p:outputLabel value="#{venda.flagVendaAtiva}" />
						</p:column>
						<f:facet name="footer">
							<p:commandButton process="Listarvendas"
								update=":form:produtoDetail" icon="ui-icon-search"
								value="Visualizar produtos"
								oncomplete="PF('mostrarProdutos').show()" />
						</f:facet>
					</p:dataTable>

					<p:dialog header="Produtos" widgetVar="mostrarProdutos"
						modal="true" appendTo="@(body)" showEffect="fade"
						hideEffect="fade" resizable="false">
						<p:outputPanel id="produtoDetail" style="text-align:center;">
							<h:panelGrid columns="2"
								rendered="#{not empty beanVenda.vendaSelecionada}">
								<ui:repeat value="#{beanVenda.vendaSelecionada.produto}"
									var="produto">
									<h:outputText value="#{produto.descricao}" />
									<h:outputText value=" - " />
									<h:outputText value="#{produto.valor}">
										<f:convertNumber currencyCode="BRL" type="currency" />
									</h:outputText>
									<br />
								</ui:repeat>
							</h:panelGrid>
						</p:outputPanel>
					</p:dialog>
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>

</html>